//////////////////////////////////////////////////////////////////////////
#include <RocketLua/RocketLua.hpp>


using namespace Rocket::Core::Lua;


Colorb::Colorb()
:	mR( 0 )
,	mG( 0 )
,	mB( 0 )
,	mA( 0 )
{
}


Colorb::Colorb( uint8_t r, uint8_t g, uint8_t b, uint8_t a )
:	mR( r )
,	mG( g )
,	mB( b )
,	mA( a )
{
}


Colorb& Colorb::Set( uint8_t r, uint8_t g, uint8_t b, uint8_t a )
{
	mR	=	r;
	mG	=	g;
	mB	=	b;
	mA	=	a;
	return *this;
}

bool Colorb::operator ==( const Colorb& rhs ) const
{
	return mR==rhs.mR && mG==rhs.mG && mB==rhs.mB && mA==rhs.mA;
}


Colorb Colorb::operator +( const Colorb& rhs ) const
{
	return Colorb( mR+rhs.mR, mG+rhs.mG, mB+rhs.mB, mA+rhs.mA );
}


Colorb Colorb::operator -( const Colorb& rhs ) const
{
	return Colorb( mR-rhs.mR, mG-rhs.mG, mB-rhs.mB, mA-rhs.mA );
}


Colorb Colorb::operator *( uint8_t rhs ) const
{
	return Colorb( mR*rhs, mG*rhs, mB*rhs, mA*rhs );
}


Colorb Colorb::operator /( uint8_t rhs ) const
{
	return Colorb( mR/rhs, mG/rhs, mB/rhs, mA/rhs );
}


uint8_t Colorb::R() const
{
	return mR;
}


uint8_t Colorb::G() const
{
	return mG;
}


uint8_t Colorb::B() const
{
	return mB;
}


uint8_t Colorb::A() const
{
	return mA;
}


void Colorb::R( uint8_t r )
{
	mR	=	r;
}


void Colorb::G( uint8_t g )
{
	mG	=	g;
}


void Colorb::B( uint8_t b )
{
	mB	=	b;
}


void Colorb::A( uint8_t a )
{
	mA	=	a;
}


void Colorb::Register( lua_State* state )
{
	luabridge::getGlobalNamespace( state )
		.beginClass< Colorb >( "Colorb" )
		.addConstructor< void (*)( void ) >()
		.addProperty( "r", &Colorb::R, &Colorb::R )
		.addProperty( "g", &Colorb::G, &Colorb::G )
		.addProperty( "b", &Colorb::B, &Colorb::B )
		.addProperty( "a", &Colorb::A, &Colorb::A )
		.addFunction( "Set", &Colorb::Set )
		.addFunction( "__eq", &Colorb::operator == )
		.addFunction( "__add", &Colorb::operator + )
		.addFunction( "__sub", &Colorb::operator - )
		.addFunction( "__mul", &Colorb::operator * )
		.addFunction( "__div", &Colorb::operator / )
		.endClass();
}
